package com.hotelsystem.dao;

import com.hotelsystem.pojo.Customer;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.websocket.server.PathParam;
import java.util.List;
import java.util.Map;

public interface CustomerMapper {

    /**
     * 根据身份证号模糊查询客户信息
     *
     * @param idNumber 身份证号
     * @return
     * @throws Exception
     */
    @Select("select * from t_customer where id_number like concat('%',#{idNumber},'%')")
    List<Customer> list(String idNumber) throws Exception;

    /**
     * 根据身份证号获取客户信息
     *
     * @param idNumber 身份证号
     * @return
     * @throws Exception
     */
    @Select("select * from t_customer where id_number = #{idNumber}")
    Customer get(String idNumber) throws Exception;

    /**
     * 添加客户
     * @param customer
     * @return
     * @throws Exception
     */
    @Insert("insert into t_customer values(null,#{name},#{sex},#{phone},#{address},#{birthday},#{idNumber},#{idType},#{nation},#{member},1)")
    @Options(useGeneratedKeys = true,keyProperty = "customerId",keyColumn = "customer_id") //将添加完的主键映射到实体类
    Integer insert(Customer customer) throws Exception;

    /**
     * 修改客户
     * @param customer
     * @return
     * @throws Exception
     */
    @Update("update t_customer set `name` = #{name},sex = #{sex},phone = #{phone},address = #{address},birthday = #{birthday},id_type = #{idType},nation = #{nation},member = #{member} where customer_id = #{customerId}")
    Integer update(Customer customer) throws Exception;

    /**
     * 按条件查询用户信息
     * @return
     */
    public List<Customer> findCustomerList(Map<String, Object> map) throws Exception;

    /**
     * 删除信息
     * @param customerId
     * @return
     * @throws Exception
     */
    public Integer deleteCustomer(@PathParam("customerId") Integer customerId) throws Exception;

    /**
     * 根据id查询
     * @param customerId
     * @return
     */
    public Customer findCustomerById(Integer customerId);
    /**
     * 修改用户信息
     * @param customer
     * @return
     * @throws Exception
     */
    public Integer updateCustomer(Customer customer) throws Exception;
}